package edu.vt.cbil.main;

import edu.vt.cbil.dataset.ConfigObject;
import edu.vt.cbil.dataset.RawData;
import edu.vt.cbil.dataset.ResultData;
import edu.vt.cbil.dataset.SNPInfo;
import edu.vt.cbil.input.Classify;
import edu.vt.cbil.input.ReadData;
import edu.vt.cbil.output.BioLogger;
import edu.vt.cbil.output.WriteFile;
import edu.vt.cbil.permute.Permute;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Logger;

/**
 * Created by SunMing on 2016/6/20.
 */
public class Main {
    public static void main(String[] args){
        Logger m_log;
        m_log=Logger.getLogger("edu.vt.cbil.permute");
        double t1=System.currentTimeMillis();
        ConfigObject conf = new ConfigObject();
        conf.readConfig("settings.xml");

        Date date = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmss");
        String filename = String.format("Result_%s_%s.log", conf.getChrName(),df.format(date));
        BioLogger log = new BioLogger(conf.getSAICResultPath(), filename);
        date = null;
        df = null;

        ArrayList<SNPInfo> snpInfos=new ArrayList<>();
        ArrayList<RawData> rawDatas=new ArrayList<>();

        ReadData readData=new ReadData();
        readData.read(conf, snpInfos, rawDatas);

        ArrayList<RawData> ampRawDatas=new ArrayList<>();
        ArrayList<RawData> delRawDatas=new ArrayList<>();
        new Classify().classify(rawDatas, ampRawDatas, delRawDatas);

        ArrayList<ResultData> ampResultDatas=new ArrayList<>();
        ArrayList<ResultData> delResultDatas=new ArrayList<>();
        Permute ampPermute=new Permute(ampRawDatas,ampResultDatas);
        m_log.info(conf.getChrName()+" amp:");
        ampPermute.processing();
        Permute delPermute=new Permute(delRawDatas,delResultDatas);
        m_log.info("\n");
        m_log.info(conf.getChrName()+" del:");
        delPermute.processing();

        String type="amp";
        WriteFile ampWriteFile=new WriteFile(ampResultDatas,snpInfos,conf,type);
        ampWriteFile.write();
        type="del";
        WriteFile delWriteFile=new WriteFile(delResultDatas,snpInfos,conf,type);
        delWriteFile.write();

        double t2=System.currentTimeMillis();

        m_log.info("\n");
        m_log.info("The run time is: "+(t2-t1)+" ms.");
    }
}
